package cn.hxzy.controller;


import cn.hxzy.common.Result;
import cn.hxzy.common.util.RandomId;
import cn.hxzy.entity.order.RunRoute;
import cn.hxzy.entity.order.vo.AddCityVo;
import cn.hxzy.entity.siteEntity.Site;
import cn.hxzy.service.SiteService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hk
 * @since 2023-06-23
 */
@CrossOrigin
@RestController
@RequestMapping("/site")
public class SiteController {
    @Autowired
    private SiteService siteService;
    @GetMapping("/{id}")
    public Result selectById(@PathVariable String id){
        Site site = siteService.getById(id);
        if (Objects.isNull(site)){
            return Result.error();
        }
        return Result.ok().data1(site);
    }

    @GetMapping
    public Result selectList(){
        List<Site> list = siteService.list();
        if (list==null){
            return Result.error();
        }
        return Result.ok().data1(list);
    }
    @GetMapping("selectByName/{loadingName}")
    public Result selectByName(@PathVariable String loadingName){
        QueryWrapper<Site> siteQueryWrapper = new QueryWrapper<>();
        siteQueryWrapper.eq("city",loadingName);
        List<Site> list = siteService.list(siteQueryWrapper);
        return Result.ok().data1(list);
    }
    @GetMapping("selectByNameUn/{unLoadingName}")
    public Result selectByNameUn( @PathVariable String unLoadingName){
        QueryWrapper<Site> siteQueryWrapper = new QueryWrapper<>();
        siteQueryWrapper.eq("city",unLoadingName);
        List<Site> list = siteService.list(siteQueryWrapper);
        return Result.ok().data1(list);
    }
    @GetMapping("selectCity")
    public Result selectCity(){
         List<Site> list = siteService.list();
         return Result.ok().data1(list);
    }
//    @PostMapping("addCity")
//    public Result addCity(@RequestBody RunRoute runRoute){
//        runRoute.setRunId(RandomId.getRunId());
//
//    }
}

